#

| Chapter 31 Creating Custom Commands in vi |

## 31.13 Making Cursor Keys Work in vi Text-input Mode

Here is my .exrc file, which I customized for a VT100 terminal. It is set up for C and nroff -me macros. [Strings like `^[OD` are set by the cursor keys (41.12) on VT100-type terminals. Make the `^[` by typing `[CTRL-v]` `[ESC]`. Many vi versions make this easier; they understand `map #1` (31.2) to mean "map function key F1."-JP ]

    troff
    set ai redraw sm wm=1
    set tabstop=4
    set shiftwidth=4
    map! {} {^M}^[O^I     Great for auto indenting { } pairs
    map! ^[OD ^[ha        Cursor left while inputting
    map! ^[OA ^[ka        Cursor up while inputting
    map! ^[OB ^[ja        Cursor down while inputting
    map! ^[OC ^[la        Cursor right while inputting
    map  ^[OP A           Mapped F1 to append to end of line
    map! ^[OP ^[A         Text-input mode of the above
    map  ^[OQ 0i          Mapped F2 to insert before line
    map! ^[OQ ^[0i        Text-input mode of the above
    map! ``  \*(lq        troff left quote
    map! ''  \*(rq        troff right quote

I can use the cursor keys while inputting text. This is handy because I can back up and add text without pressing ESC. [Though you may not be able to (31.3) undo your previous change with the u command. -JP ]

Also, I have defined `[F1]` to append at the end of the line. This is useful because it doesn't matter what mode you are in, it always puts you in text-input mode.

At one time, I mapped the entire numeric keypad to emulate the EDT editor.

- BB in net.unix on Usenet, 9 October 1986

31.12 Text-Input Mode Cursor Motion with No Arrow Keys |  | 31.14 Don't Lose Important Functions with vi Maps: Use noremap